//
//  NaoLingSettingController.m
//  SleepingElf
//
//  Created by karong on 2023/10/25.
//

#import "NaoLingSettingController.h"

@interface NaoLingSettingController ()
@property (weak, nonatomic) IBOutlet UICollectionView *listView;
@property (nonatomic, strong) NSArray * dataArray;
@property (nonatomic, assign) NSInteger selectIndex;
@end

@implementation NaoLingSettingController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.clearColor;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"kcell" forIndexPath:indexPath];
    UILabel * label = [cell viewWithTag:101];
    label.text = self.dataArray[indexPath.row][@"title"];
    UIView * view = [cell viewWithTag:102];
    view.hidden = !(([self.dataArray[indexPath.row][@"file"] isEqualToString:appConfig.xiaoQiConfig.url] && self.type == 1) || ([self.dataArray[indexPath.row][@"file"] isEqualToString:appConfig.sleepConfig.url] && self.type == 2));
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGSize size = CGSizeZero;
    size.width = SEScreenWidth - 13 - 13;
    size.height = 74;
    return size;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    self.selectIndex = indexPath.row;
    [self.listView reloadData];
    if ([self.delegate respondsToSelector:@selector(naoLingSettingControllerDidSelectWithObject:)]) {
        [self.delegate naoLingSettingControllerDidSelectWithObject:self.dataArray[indexPath.row]];
    }
}

- (NSArray *)dataArray {
    if (!_dataArray) {
        _dataArray = @[@{@"title":WSLocalized(@"下雨天"),
                         @"file":@"rain"},
                       @{@"title":WSLocalized(@"农夫渔夫"),
                         @"file":@"nfyf"},
                       @{@"title":WSLocalized(@"农家清晨"),
                         @"file":@"njqc"},
                       @{@"title":WSLocalized(@"摩擦声响"),
                         @"file":@"mcsx"},
                       @{@"title":WSLocalized(@"欢乐乐章"),
                         @"file":@"hlyz"},
                       @{@"title":WSLocalized(@"虫鸣鸟叫"),
                         @"file":@"cmnj"},
                       @{@"title":WSLocalized(@"金币散落"),
                         @"file":@"jbsl"},
                       @{@"title":WSLocalized(@"钢琴声"),
                         @"file":@"gqs"},
        ];
    }
    return _dataArray;
}
@end
